package xyz.scootaloo.oj.leetcode

import org.junit.Test
import xyz.scootaloo.common.TestDsl
import kotlin.math.min

/**
 * @author flutterdash@qq.com
 * @since 2021/7/3 11:08
 */
class P746 : TestDsl {

    private fun minCostClimbingStairs(cost: IntArray): Int {
        fun fib(): Int {
            val steps = IntArray(cost.size + 1)
            steps[0] = cost[0]
            steps[1] = cost[1]
            for (i in 2 until cost.size) {
                steps[i] = min(steps[i - 2], steps[i - 1]) + cost[i]
            }
            return min(steps[cost.size - 1], steps[cost.size - 2])
        }

        return fib()
    }

    @Test
    fun test0() {
        val cost1 = intArrayOf(10, 15, 20)
        minCostClimbingStairs(cost1) shouldBe 15
        val cost2 = intArrayOf(1, 100, 1, 1, 1, 100, 1, 1, 100, 1)
        minCostClimbingStairs(cost2) shouldBe 6
    }

}
